﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

namespace EDMS.SMS
{
    public partial class Dialog : System.Web.UI.Page
    {
        /// <summary>
        /// 短信列表
        /// </summary>
        protected List<DAL.Dxjl> Dxs
        {
            get
            {
                if (Request.QueryString["phone"] == null)
                {
                    return null;
                }
                else
                {
                    string phone = Request.QueryString["phone"];
                    using (DAL.DataClassesDataContext dc = new DAL.DataClassesDataContext())
                    {
                        var dxs = dc.Dxjl.Where(d => d.mbsjhm.Equals(phone) || d.bjhm.Equals(phone)).OrderByDescending(d => d.fssj);
                        return dxs.ToList();
                    }
                }
            }
        }

        /// <summary>
        /// 选民姓名 
        /// </summary>
        protected string XmName
        {
            get
            {
                if (Request.QueryString["phone"] == null)
                {
                    return string.Empty;
                }
                else
                {
                    string phone = Request.QueryString["phone"];
                    using (DAL.DataClassesDataContext dc = new DAL.DataClassesDataContext())
                    {
                        DAL.Xm xm = dc.Xm.FirstOrDefault(x => x.sjhm.Equals(phone));
                        if (xm == null)
                        {
                            return phone;
                        }
                        else
                        {
                            return xm.xmxm;
                        }
                    }
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        /// <summary>
        /// 按指定长度给短信加上换行符
        /// </summary>
        /// <param name="nr">短信内容</param>
        /// <returns></returns>
        protected string RebuildContent(string nr)
        {
            StringBuilder P_stringbuilder = new StringBuilder(nr);
            for (int i = 0; i < P_stringbuilder.Length; i++)
            {
                if (i % 60 == 0 && i != 0)
                {
                    P_stringbuilder.Insert(++i, "</br>");
                }
            }
            return P_stringbuilder.ToString();
        }
    }
}